import Wx from "../utils/Wx";
import CustomError from "../utils/CustomError";
module.exports = {

    /*
    * 增加寻丢记录
    * */
    addRecord: async function (data = {}) {
        try {
            return await Wx.cloudFunction("record", Object.assign(
                {actionName: "addRecord"},
                data
            ))
        } catch (e) {
            throw new CustomError(e, "Record.addRecord").parse()
        }
    },

    /*
    * 获取记录详情
    * */
    getRecordDetail: async function (id) {
        try {
            return await Wx.cloudFunction("record", {
                actionName: "getRecordDetail",
                id: id
            })
        } catch (e) {
            throw new CustomError(e, "Record.getRecordDetail").parse()
        }
    },

    /*
    * 获取记录列表
    * */
    getRecordList: async function (data = {}) {
        try {
            return await Wx.cloudFunction("record", Object.assign(
                {actionName: "getRecordList"},
                data
            ))
        } catch (e) {
            throw new CustomError(e, "Record.getRecordList").parse()
        }
    },

    /*
    * 删除记录
    * */
    deleteRecord: async function (id) {
        try {
            return await Wx.cloudFunction("record", {
                actionName: "deleteRecord",
                id: id
            })
        } catch (e) {
            throw new CustomError(e, "Record.deleteRecord").parse()
        }
    },

    /*
    * 更新记录
    * */
    updateRecord: async function (id, data = {}) {
        try {
            return await Wx.cloudFunction("record", Object.assign(
                {actionName: "updateRecord"},
                {id: id},
                data
            ))
        } catch (e) {
            throw new CustomError(e, "Record.updateRecord").parse()
        }
    },

    /*
    * 获取记录总数
    * */
    getRecordCount: async function () {
        try {
            return await Wx.cloudFunction("record", {
                actionName: "getRecordCount"
            })
        } catch (e) {
            throw new CustomError(e, "Record.getRecordCount").parse()
        }
    },
}